package com.demo.mapper;

import com.demo.dto.CoursePageQueryDTO;
import com.demo.dto.LeaveDTO;
import com.demo.dto.LeavePageQueryDTO;
import com.demo.pojo.Classes;
import com.demo.pojo.Leave;
import com.demo.vo.CourseVO;
import com.demo.vo.LeaveVO;
import com.github.pagehelper.Page;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface LeaveMapper {
    @Insert("insert into sys_leave (leaveID,courseID,reason,daynum,stuNo,applytime,status) " +
            "values (#{leaveID},#{courseID},#{reason},#{daynum},#{stuNo},#{applytime},#{status});")
    void addLeave(Leave leave);

    @Delete("delete from sys_leave where leaveID=#{leaveID} and status!='2'")
    int delete(String leaveID);

    @Select("<script>" +
            "SELECT l.*, " +
            "c.courseName AS courseName " +
            "FROM sys_leave l " +
            "LEFT JOIN sys_course c ON l.courseID = c.courseID " +
            "WHERE 1=1 " +
            "<if test='leaveID != null and leaveID.trim() != \"\"'> " +
            "AND l.leaveID = #{leaveID} " +
            "</if> " +
            "ORDER BY l.leaveID " +
            "</script>")
    Page<LeaveVO> pageQuery(LeavePageQueryDTO LeavePageQueryDTO);

    @Select("select * from sys_leave where leaveID=#{leaveID}")
    Leave selectByLeaveID(String leaveID);

    @Select("select * from sys_classes where className=#{className}")
    Classes selectByClassName(String leaveID);

    @Update("update sys_leave set opinion=#{opinion},audittime=#{audittime},status=#{status} where leaveID=#{leaveID}")
    void update(LeaveDTO leaveDTO);
}
